// pages/mine/mine.js
import {
  ajax,
  src,
  util
} from "../../utils/util.js";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    img:'',
    name:'',
    select:'',
    islogin:false
  },
  // 授权登录
  bindGetUserInfo(e) {
    var that = this;
    if (wx.getStorageSync("uqid")){
      this.setData({
        islogin: true
      })
    }else{
      if (e.detail.userInfo) {
        wx.setStorageSync("nickName", e.detail.userInfo.nickName)
        wx.setStorageSync("avatarUrl", e.detail.userInfo.avatarUrl)
        console.log()
        // 用户按了允许授权按钮
        var code = wx.getStorageSync("code");
        ajax('/api/user/login', {
          data: {
            code: code,
            nickname: e.detail.userInfo.nickName,
            avatar: e.detail.userInfo.avatarUrl,
          },
          header: {
            'Accept': 'application/x-www-form-urlencoded', // 默认值
          },
          method: "put",
        }, res => {
          wx.setStorageSync("uqid", res.data.uqid)
          var name = wx.getStorageSync("nickName")
          var img = wx.getStorageSync("avatarUrl")
          this.setData({
            name: name,
            img: img,
            islogin: true
          })
        })
      } else {
        wx.showToast({
          title: '请先授权！',
          icon: 'none',
          duration: 2000
        })
      }
    }
    
  },
  // 订单
  order:function(){
    wx.navigateTo({
      url: '/pages/my-order/order',
    })
  },
  // 待付款
  orderfukuan:function(e){
    var idx = e.currentTarget.dataset.index;
    wx.navigateTo({
      url: '/pages/my-order/order?select=' + idx,
    })
  },
  // 待发货
  orderfahuo:function(e){
    var idx = e.currentTarget.dataset.index;
    wx.navigateTo({
      url: '/pages/my-order/order?select=' + idx,
    })
  },
  // 待收货
  ordershouhuo:function(e){
    var idx = e.currentTarget.dataset.index;
    wx.navigateTo({
      url: '/pages/my-order/order?select=' + idx,
    })
  },
  // 退款售后
  orderstuikuan:function(e){
    var idx = e.currentTarget.dataset.index;
    wx.navigateTo({
      url: '/pages/my-order/order?select=' + idx,
    })
  },
  // 0元拍
  auction:function(){
    wx.navigateTo({
      url: '/pages/my-auction/auction',
    })
  },
  // 社区
  shequ:function(){
    wx.navigateTo({
      url: '/pages/my-community/community',
    })
  },
  // 鉴宝
  jianbao:function(){
    wx.navigateTo({
      url: '/pages/my-jianbao/jianbao',
    })
  },
  //信息管理
  newsManage:function(){
    wx.navigateTo({
      url: '/pages/news-manage/manage',
    })
  },
  //收货地址
  address:function(){
    wx.navigateTo({
      url: '/pages/my-address/address',
    })
  },
  //我的收藏
  collect:function(){
    wx.navigateTo({
      url: '/pages/my-collect/collect',
    })
  },
  // 我的评论
  comment:function(){
    wx.navigateTo({
      url: '/pages/my-comment/comment',
    })
  },
  // 关于我们
  about:function(){
    wx.navigateTo({
      url: '/pages/my-about/about',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var name = wx.getStorageSync("nickName")
    var img = wx.getStorageSync("avatarUrl")
    this.setData({
      name: name,
      img: img,
    })
    if (wx.getStorageSync("uqid")) {
      this.setData({
        islogin: true
      })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})